---
apiVersion: batch/v1
kind: Job
metadata:
  name: ks-devops-migration
  namespace: kubesphere-system
  labels:
    app: ks-devops-migration
    job: ks-devops-migration
    version: v3.0.0
spec:
  backoffLimit: 6
  completions: 1
  parallelism: 1
  template:
    metadata:
      labels:
        app: ks-devops-migration
        job: ks-devops-migration
        version: v3.0.0
      name: ks-devops-migration
    spec:
      initContainers:
        - name: wait-jenkins
          image: {{ alpine_repo }}:{{ alpine_tag }}
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c', 'until wget --spider http://devops-jenkins.kubesphere-devops-system.svc/login; do echo "waiting for myservice"; sleep 2; done;']
        - name: wait-mysql
          image: {{ alpine_repo }}:{{ alpine_tag }}
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c', 'until nc -z mysql.kubesphere-system.svc 3306; do echo "waiting for mysql"; sleep 2; done;']
        - name: wait-apiserver
          image: {{ alpine_repo }}:{{ alpine_tag }}
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c', 'until nc -z ks-apiserver.kubesphere-system.svc 80; do echo "waiting for apiserver"; sleep 2; done;']
      containers:
        - command:
          - ks-upgrade
          image: {{ ks_devops_migration_repo }}:{{ ks_devops_migration_tag }}
          imagePullPolicy: IfNotPresent
          name: ks-devops-upgrade
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/kubesphere/
              name: kubesphere-config
      serviceAccount: kubesphere
      serviceAccountName: kubesphere
      volumes:
        - configMap:
            defaultMode: 420
            name: kubesphere-config
          name: kubesphere-config
      dnsPolicy: ClusterFirst
      restartPolicy: OnFailure
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
